package com.qiangesoft.blog.file.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.qiangesoft.blog.common.utils.DateUtils;
import com.qiangesoft.blog.file.entity.SysFileInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * minio文件响应
 *
 * @author qiange
 * @date 2023-04-23
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "文件响应体")
public class FileInfoVo implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "文件id")
    private Long fileId;

    @ApiModelProperty(value = "原始文件名")
    private String originalFileName;

    @ApiModelProperty(value = "文件名")
    private String fileName;

    @ApiModelProperty(value = "文件后缀")
    private String fileExtension;

    @ApiModelProperty(value = "下载地址")
    private String downloadUrl;

    @ApiModelProperty(value = "存储路径后缀")
    private String storeUrl;

    @ApiModelProperty(value = "存储方式：文件存储、minio等")
    private String storeType;

    @ApiModelProperty(value = "分类")
    private String category;

    @ApiModelProperty(value = "是否失效")
    private Boolean expireFlag;

    @ApiModelProperty(value = "文件大小（单位：字节）")
    private Long fileSize;

    @JsonFormat(pattern = DateUtils.FORMAT_STRING, timezone = "GMT+8")
    @ApiModelProperty(value = "创建时间")
    private LocalDateTime createTime;

    /**
     * entity to vo
     *
     * @param entity
     * @return
     */
    public static FileInfoVo fromEntity(SysFileInfo entity) {
        FileInfoVo vo = new FileInfoVo();
        vo.setFileId(entity.getId());
        vo.setOriginalFileName(entity.getOriginalFileName());
        vo.setFileName(entity.getFileName());
        vo.setStoreUrl(entity.getStoreUrl());
        vo.setStoreType(entity.getStoreType());
        vo.setFileSize(entity.getFileSize());
        vo.setCategory(entity.getCategory());
        vo.setExpireFlag(entity.getExpireFlag());
        vo.setFileExtension(entity.getFileExtension());
        vo.setCreateTime(entity.getCreateTime());
        return vo;
    }
}